﻿/*
* Copyright (c) 2010-2012 Tesla Engine Group
* 
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* 
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/


namespace Tesla.Math {
    /// <summary>
    /// A record of a single Ray-Object intersection.
    /// </summary>
    public struct IntersectionRecord {
        private Vector3 _point;
        private Vector3? _normal;
        private float _distance;
        private Triangle? _triangle;

        /// <summary>
        /// Gets the point of intersection.
        /// </summary>
        public Vector3 Point {
            get {
                return _point;
            }
        }

        /// <summary>
        /// Gets the normal vector of the intersection. Optional.
        /// </summary>
        public Vector3? Normal {
            get {
                return _normal;
            }
        }

        /// <summary>
        /// Gets the distance of the intersection from the Ray's
        /// origin.
        /// </summary>
        public float Distance {
            get {
                return _distance;
            }
        }

        /// <summary>
        /// Gets the triangle that the point is located on, if any. Optional.
        /// </summary>
        public Triangle? Triangle {
            get {
                return _triangle;
            }
        }

        /// <summary>
        /// Creates a new intersection record without a normal.
        /// </summary>
        /// <param name="point">Point of intersection</param>
        /// <param name="distance">Distance from the ray's origin</param>
        public IntersectionRecord(Vector3 point, float distance) {
            _point = point;
            _normal = null;
            _distance = distance;
            _triangle = null;
        }

        /// <summary>
        /// Creates a new intersection record.
        /// </summary>
        /// <param name="point">Point of intersection</param>
        /// <param name="normal">Normal of the intersection</param>
        /// <param name="distance">Distance from the ray's origin</param>
        public IntersectionRecord(Vector3 point, Vector3 normal, float distance) {
            _point = point;
            _normal = normal;
            _distance = distance;
            _triangle = null;
        }

        /// <summary>
        /// Creates a new intersection record.
        /// </summary>
        /// <param name="point">Point of intersection</param>
        /// <param name="normal">Normal of the intersection</param>
        /// <param name="distance">Distance from the ray's origin</param>
        /// <param name="triangle">The triangle</param>
        public IntersectionRecord(Vector3 point, Vector3 normal, float distance, Triangle triangle) {
            _point = point;
            _normal = normal;
            _distance = distance;
            _triangle = triangle;
        }
    }
}
